﻿namespace SimbaRGVMonitor.Models
{
    class Vertex
    {
        public Vertex(
            string vertexNo, float positionX,
            float positionY, bool isOccupied, string arrivedRobot)
        {
            this.vertexNo = vertexNo;
            this.positionX = positionX;
            this.positionY = positionY;
            this.isOccupied = isOccupied;
            this.arrivedRobot = arrivedRobot;
        }

        //====================================================================================================
        //以上是类型构造函数
        //----------------------------------------------------------------------------------------------------
        //以下是类型字段
        //====================================================================================================

        private readonly string vertexNo;
        private readonly float positionX;
        private readonly float positionY;
        private readonly bool isOccupied;
        private readonly string arrivedRobot;

        //====================================================================================================
        //以上是类型字段
        //----------------------------------------------------------------------------------------------------
        //以下是类型属性
        //====================================================================================================

        public string VertexNo
        {
            get { return vertexNo; }
        }

        public float PositionX
        {
            get { return positionX; }
        }

        public float PositionY
        {
            get { return positionY; }
        }

        public bool IsOccupied
        {
            get { return isOccupied; }
        }

        public string ArrivedRobot
        {
            get { return arrivedRobot; }
        }

        //====================================================================================================
        //以上是类型属性
        //----------------------------------------------------------------------------------------------------
        //以下是重载操作符==及!=
        //====================================================================================================

        public static bool operator ==(Vertex left, Vertex right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(Vertex left, Vertex right)
        {
            return Equals(left, right) == false;
        }

        //====================================================================================================
        //以上是重载操作符==及!=
        //----------------------------------------------------------------------------------------------------
        //以下是重写Equals及GetHashCode
        //====================================================================================================

        public override bool Equals(object obj)
        {
            var other = obj as Vertex;
            return other != null &&
                other.vertexNo == vertexNo &&
                other.positionX == positionX &&
                other.positionY == positionY &&
                other.isOccupied == isOccupied &&
                other.arrivedRobot == arrivedRobot;
        }

        public override int GetHashCode()
        {
            var hashCode = vertexNo == null ? string.Empty.GetHashCode() : vertexNo.GetHashCode();
            hashCode ^= positionX.GetHashCode();
            hashCode ^= positionY.GetHashCode();
            hashCode ^= isOccupied.GetHashCode();
            hashCode ^= arrivedRobot == null ? string.Empty.GetHashCode() : arrivedRobot.GetHashCode();
            return hashCode;
        }
    }
}
